package com.example.sheji;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.DialogInterface;
import androidx.appcompat.app.AlertDialog;




public class MainActivity4 extends AppCompatActivity {

    private static final int OUT = 1;
    private static final int IN = 2;
    private DBManager mgr;
    private EditText name,sex,birth,number,phone,person,tim;
    //private EditText etCount,etDescribe;
    private RadioGroup radioGroup;
    private TextView tvInfo;
    private Button btnAdd;
    private Button butyu;
    private Button kang;
    private int countType = OUT;




    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        //初始化DBManager
        mgr = new DBManager(this);
        name = (EditText) findViewById(R.id.name);
        sex = (EditText) findViewById(R.id.sex);
        birth = (EditText) findViewById(R.id.birth);
        number = (EditText) findViewById(R.id.number);
        phone = (EditText) findViewById(R.id.phone);
        person = (EditText) findViewById(R.id.person);
        tim = (EditText) findViewById(R.id.tim);
        //etCount = (EditText) findViewById(R.id.etCount);
        //etDescribe = (EditText) findViewById(R.id.etDescribe);
        /*radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        tvInfo = (TextView)findViewById(R.id.tvInfo);*/
        btnAdd = (Button)findViewById(R.id.button1);
        kang = (Button)findViewById(R.id.kang);

        /*radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radioOut:
                        countType = OUT;
                        break;
                    case R.id.radioIn:
                        countType = IN;
                        break;
                }
            }
        });*/
        kang = (Button) findViewById(R.id.kang);
        kang.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(getApplicationContext(),MainActivity.class);
                        startActivity(intent);
                    }
                }

        );


        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Count count = new Count();
                long time = System.currentTimeMillis();
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String str = format.format(new Date(time));
                count.setDate(str);
                count.setName(name.getText().toString());
                count.setSex(sex.getText().toString());
                count.setBirth(birth.getText().toString());
                count.setNumber(Double.parseDouble(number.getText().toString()));
                count.setPhone(Double.parseDouble(phone.getText().toString()));
                count.setPerson(person.getText().toString());
                count.setTim(tim.getText().toString());

                mgr.insert(count);      //插入数值
                //resetInfo();
                Intent intent = new Intent(MainActivity4.this,MainActivity7.class);
                startActivity(intent);
            }
        });
        //resetInfo();
        butyu = (Button) findViewById(R.id.button2);
        butyu.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(getApplicationContext(),PrintActivity.class);
                        startActivity(intent);
                    }
                }

        );

    }


    /*public void resetInfo(){
        Double out = mgr.getResult(OUT);
        Double in = mgr.getResult(IN);
        Double all = in - out;
        tvInfo.setText("总计支出："+out+"  总计收入："+in+" 结余：" +all+"。");
    }*/

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //应用的最后一个Activity关闭时应释放DB
        mgr.closeDB();
    }
}
